package cn.edu.sgu.www.mhxysy.controller.baoshi;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.baoshi.EquipmentViewBaoshiDTO;
import cn.edu.sgu.www.mhxysy.entity.baoshi.EquipmentViewBaoshi;
import cn.edu.sgu.www.mhxysy.pager.baoshi.EquipmentBaoshiPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.baoshi.EquipmentViewBaoshiService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "装备预览宝石管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/equipment_view_baoshi", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class EquipmentViewBaoshiController {

	private final EquipmentViewBaoshiService equipmentViewBaoshiService;

	@Autowired
	public EquipmentViewBaoshiController(EquipmentViewBaoshiService equipmentViewBaoshiService) {
		this.equipmentViewBaoshiService = equipmentViewBaoshiService;
	}

	@ApiOperation("添加装备预览宝石")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated EquipmentViewBaoshiDTO equipmentViewBaoshiDTO) {
		equipmentViewBaoshiService.insert(equipmentViewBaoshiDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID修改装备预览宝石")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated EquipmentViewBaoshiDTO equipmentViewBaoshiDTO) {
		equipmentViewBaoshiService.updateById(equipmentViewBaoshiDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("查询宝石可镶嵌的装备名称列表")
	@RequestMapping(value = "/selectInlayEquipments", method = RequestMethod.GET)
	public JsonResult<List<String>> selectInlayEquipments(
			@ApiParam(name = "baoshiId", value = "宝石类型ID", required = true)
			@NotNull(message = "宝石类型" + CustomMessages.ID_NOT_NULL) Integer baoshiId) {
		List<String> list = equipmentViewBaoshiService.selectInlayEquipments(baoshiId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("分页查询装备预览宝石列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<EquipmentViewBaoshi>> selectByPage(EquipmentBaoshiPager pager) {
		Page<EquipmentViewBaoshi> page = equipmentViewBaoshiService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}